package dev.ece.suit.loader.models.ms3d;

import java.io.IOException;

import dev.ece.suit.loader.Material;
import dev.ece.util.io.LittleEndianInputStream;

public class MS3DMaterial extends Material {

	private String name;
	
	private String comment;
	
	private MS3DMaterial() {}
	
	public static MS3DMaterial[] load(LittleEndianInputStream is) throws IOException {
		MS3DMaterial[] materials = new MS3DMaterial[is.readUnsignedShort()];
		MS3DMaterial material = null;
		for(int i=0; i<materials.length; i++) {
			materials[i] = material = new MS3DMaterial();
			material.name = is.readString(32);
			is.readFloat();
			is.readFloat();
			is.readFloat();
			is.readFloat();
			material.getDiffuse().set(is.readFloat(), is.readFloat(), is.readFloat());
			is.readFloat();
			material.getSpecular().set(is.readFloat(), is.readFloat(), is.readFloat());
			is.readFloat();
			is.readFloat();
			is.readFloat();
			is.readFloat();
			is.readFloat();
			material.setShininess(is.readFloat());
			is.skip(5);
			material.setTextureName(is.readString(128));
			is.skip(128);
		}
		return materials;
	}
	
	public static void loadComment(LittleEndianInputStream is, MS3DMaterial[] materials) throws IOException {
		int count = is.readInt();
		MS3DMaterial material = null;
		long commentSize = 0;
		for(int i=0; i<count; i++) {
			material = materials[is.readInt()];
			commentSize = is.readUnsignedInt();
			if(commentSize > 0) {
				material.comment = is.readString((int) commentSize);
			}
		}
	}

	public String getName() {
		return name;
	}

	public String getComment() {
		return comment;
	}
	
}
